﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Data.NHibernate.Generic.Support;
using YiLe.DAL.Dao;

namespace YiLe.DAL.NHibernate
{
    public class BaseHibernate<TEntity, TId> : HibernateDaoSupport, IDao<TEntity, TId>
    {
        public IList<TEntity> GetAll()
        {
            return HibernateTemplate.LoadAll<TEntity>();
        }

        public TEntity Get(TId id)
        {
            return HibernateTemplate.Get<TEntity>(id);

        }

        public TId Save(TEntity entity)
        {
            return (TId)HibernateTemplate.Save(entity);
        }

        public void Update(TEntity entity)
        {
            HibernateTemplate.SaveOrUpdate(entity);
        }

        public void Delete(TEntity entity)
        {
            HibernateTemplate.Delete(entity);
        }

        public void Delete(TEntity entity, TId id)
        {
            HibernateTemplate.Delete(Get(id));
        }
    }
}
